<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.w3.org/1999/xhtml">
<head>
    <meta charset="utf-8">
    <title>忘记密码</title>
    <base href="/">
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="static/lib/layui-v2.6.3/css/layui.css" media="all">
    <link rel="stylesheet" href="static/css/public.css" media="all">
</head>
<style>
    .layuia-form-item .layui-input-company {width: auto;padding-right: 10px;line-height: 38px;}
    #sendCode{
        position: absolute;
        top: 0;
        right: 0;
    }
</style>
<body style="background: #FFF">
<div style="margin-top: 50px">
    <div class="layuimini-main">
        <form id="addForm" class="layui-form layui-form-pane">
            <div class="layui-form-item">
                <label class="layui-form-label required">帐号</label>
                <div class="layui-input-block">
                    <input type="text" id="managerAccount" name="managerAccount" lay-verify="required" lay-reqtext="旧的密码不能为空" value="" class="layui-input">
                    <a id="sendCode" class="layui-btn layui-btn-normal">发送验证码</a>
                </div>
            </div>
            <div id="captchaDIV" class="layui-form-item">
                <div lay-filter="myDiv">
                    <label class="layui-form-label">验证码</label>
                    <div class="layui-input-block">
                        <input id="captcha" name="captcha" type="text" class="layui-input">
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label required">新的密码</label>
                <div class="layui-input-block">
                    <input type="password" id="newPassword" name="newPassword" lay-verify="required" lay-reqtext="新的密码不能为空" value="" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label required">确认密码</label>
                <div class="layui-input-block">
                    <input type="password" id="againPassword" name="againPassword" lay-verify="required" lay-reqtext="新的密码不能为空"  value="" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-input-block" style="margin: auto;text-align: center;">
                    <button id="#subbtn" style="width: 180px" class="layui-btn layui-btn-normal" lay-submit lay-filter="saveBtn">确认修改</button>
                </div>
            </div>
        </form>
    </div>
</div>
<script src="static/lib/layui-v2.6.3/layui.js" charset="utf-8"></script>
<script src="static/js/lay-config.js?v=1.0.4" charset="utf-8"></script>
<script src="static/lib/jquery-3.4.1/jquery-3.4.1.min.js"></script>
<script th:inline="javascript">
    let data={
        managerAccount: null,
        newPassWord: null
    }

    $(function (){
        let MailData={
            mail:null,
            checkCode:null
        }
        //提交表单
        $('#addForm').submit(function (e) {
            MailData.mail= $('#managerAccount').val();
            MailData.checkCode=$('#captcha').val();
            $.ajax({
                type: "post",
                url: '/util/check/mail',
                data: MailData,
                success: function () {
                    let newPassword=$('#newPassword').val();
                    let againPassword=$('#againPassword').val();
                    if (newPassword !== againPassword) {
                        layer.msg("两次输入密码不一致");
                        e.preventDefault();
                        return false;
                    }
                    data.managerAccount = $('#managerAccount').val();
                    data.newPassWord = newPassword;
                    $.ajax({
                        type: "post",
                        url: '/manager/changePassWord',
                        data: data,
                        success: function (res) {
                            if (res.code === 200) {
                                layer.msg(res.message, {time: 2000, icon: 1, offset: [15]});
                                let index=parent.layer.getFrameIndex(window.name);
                                setTimeout(function (){
                                    window.parent.location.reload();//刷新父页面
                                    parent.layer.close(index);
                                },1500);
                            } else {
                                layer.msg(res.message, {time: 2000, icon: 1, offset: [15]});
                            }
                        },
                        error: function (error) {
                            layer.msg(error, {time: 2000, icon: 2, offset: [15]});
                        }
                    })
                    e.preventDefault();
                },
                error: function (error) {
                    layer.msg(error, {time: 2000, icon: 2, offset: [15]});
                }
            })
            e.preventDefault();
        });

        //发送验证码
        $('#sendCode').click(function (){
            let to=$('#managerAccount').val();
            let load = layer.load(0, {shade: false}); //0代表加载的风格，支持0-2
            $.ajax({
                type:"post",
                url:'/sms/sendCodeMail',
                data:{
                    to:to,
                    userName:to
                },
                success:function (res){
                    if(res.code===200){
                        layer.msg(res.message,{time:5000,icon:1,offset:[15]});
                    }else{
                        layer.msg(res.message,{time:5000,icon:1,offset:[15]});
                    }
                },
                error:function (error){
                    layer.msg(error,{time:5000,icon:2,offset:[15]});
                },
                complete:function () {
                    layer.close(load)
                }
            })
        });


    });



</script>
</body>
</html>